#!/bin/bash
# Test compilation of all generated C++ files

cd "$(dirname "$0")"

success=0
total=0
failed_files=()

for file in $(find . -name "*.cpp" | grep -v __pycache__ | sort); do
  total=$((total + 1))
  echo "[$total] Compiling: $file"

  if g++ -std=c++17 -c "$file" -I. -I$(dirname "$file") -o /tmp/test_$total.o 2>/dev/null; then
    echo "    ✓ SUCCESS"
    success=$((success + 1))
  else
    echo "    ✗ FAILED"
    failed_files+=("$file")
    # Show first few errors
    g++ -std=c++17 -c "$file" -I. -I$(dirname "$file") -o /tmp/test_$total.o 2>&1 | head -10
  fi
  echo ""
done

echo "========================================"
echo "Compilation Results:"
echo "  Success: $success/$total files"
percent=$((success * 100 / total))
echo "  Rate: ${percent}%"
echo ""

if [ ${#failed_files[@]} -gt 0 ]; then
  echo "Failed files:"
  for f in "${failed_files[@]}"; do
    echo "  - $f"
  done
fi
